﻿using Capstone.Models;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace Capstone.ViewModels
{
    [QueryProperty(nameof(ItemId), nameof(ItemId))]
    public class GutSymptomViewModel : BaseViewModel
    {
        private string itemId;
        private string text;
        private string description;
        public string Id { get; set; }

        private int length;
        private string frequency;
        private string[] symptoms;
        private string[] othersymptoms;
        private string[] sleepsymptoms;

        public string Text
        {
            get
            {
                return text;
            }

            set
            {
                SetProperty(ref text, value);
            }
        }
        public int Length
        {
            get => length;
            set => SetProperty(ref length, value);
        }

        public string Frequency
        {
            get => frequency;
            set => SetProperty(ref frequency, value);
        }

        public string[] Symptoms
        {
            get => symptoms;
            set => SetProperty(ref symptoms, value);
        }
        public string[] OtherSymptoms
        {
            get => othersymptoms;
            set => SetProperty(ref othersymptoms, value);
        }
        public string[] SleepSymptoms
        {
            get => sleepsymptoms;
            set => SetProperty(ref sleepsymptoms, value);
        }
        public string Description
        {
            get => description;
            set => SetProperty(ref description, value);
        }

        public string ItemId
        {
            get
            {
                return itemId;
            }
            set
            {
                itemId = value;
                LoadItemId(value);
            }
        }

        public async void LoadItemId(string itemId)
        {
            try
            {
                var item = await DataStore.GetItemAsync(itemId);
                Id = item.Id;
                Text = item.Text;
                Description = item.Description;
                Frequency = item.Frequency;
                Length = item.Length;
                Symptoms = item.Symptoms;
                OtherSymptoms = item.OtherSymptoms;
                SleepSymptoms = item.SleepSymptoms;
            }
            catch (Exception)
            {
                Debug.WriteLine("Failed to Load Item");
            }
        }
    }
}
